﻿using Architecture.API.Application.TraceabilityCommand.EnterpriseCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.EnterpriseServices;

namespace Architecture.API.Application.TraceabilityCommandHandler.EnterpriseCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class AddSlaughterCommandHandler : IRequestHandler<AddSlgughterCommand, int>
    {
        /// <summary>
        /// 企业服务
        /// </summary>
        protected readonly IEnterpriseService enterpriseService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="enterpriseService">企业服务</param>
        public AddSlaughterCommandHandler(IEnterpriseService enterpriseService)
        {
            this.enterpriseService = enterpriseService;
        }

        /// <summary>
        /// 添加屠宰信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<int> Handle(AddSlgughterCommand request, CancellationToken cancellationToken)
        {
            return await enterpriseService.AddEnterpriseSlaughter(request.shoppingId, new Enterprise() { SlaughterCompanyName=request.SlaughterCompanyName,EstablishmentTime=request.EstablishmentTime,CompanyProfile=request.CompanyProfile,ProvinceId=request.ProvinceId,CityId=request.CityId,CountyId=request.CountyId, UpdatedBy = request.UpdatedBy, UpdatedDate = DateTime.Now } );
        }
    }
}
